package cn.bugstack.domain.auth.service;
import cn.bugstack.domain.auth.adapter.port.ILoginPort;
import com.google.common.cache.Cache;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.IOException;

/**
 * @Author: 小新
 * @Date: 2025/3/21 14:43
 * @Description: 微信登录服务
 * @Version: v1.0
 */

@Service
public class WeixinLoginService implements ILoginService{


    @Resource
    private ILoginPort iLoginPort;

    @Resource
    private Cache<String, String> openidToken;



    @Override
    public String createQrCodeTicket() throws Exception {
        return iLoginPort.createQrCodeTicket();
    }

    @Override
    public String checkLogin(String ticket) {
        return openidToken.getIfPresent(ticket);
    }

    @Override
    public void saveLoginState(String ticket, String openId) throws IOException {
        openidToken.put(ticket, openId);

        //发送模板消息
        iLoginPort.sendLoginTemplate(openId);
    }
}
